package com.hiultra.archive.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.hiultra.archive.domain.ArchiveDesTask;
import com.hiultra.archive.service.IArchiveDesTaskService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.page.TableDataInfo;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 销毁任务Controller
 *
 * @author paidaxing
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/archive/ArchiveDesTask")
public class ArchiveDesTaskController extends BaseController {
    @Autowired
    private IArchiveDesTaskService archiveDesTaskService;

    /**
     * 查询销毁任务列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveDesTask archiveDesTask) throws JsonProcessingException {
        startPage();
        List<ArchiveDesTask> list = archiveDesTaskService.selectArchiveDesTaskList(archiveDesTask);
        return getDataTable(list);
    }

    /**
     * 导出销毁任务列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:export')")
    @Log(title = "销毁任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveDesTask archiveDesTask) throws JsonProcessingException {
        List<ArchiveDesTask> list = archiveDesTaskService.selectArchiveDesTaskList(archiveDesTask);
        ExcelUtil<ArchiveDesTask> util = new ExcelUtil<ArchiveDesTask>(ArchiveDesTask.class);
        util.exportExcel(response, list, "销毁任务数据");
    }

    /**
     * 获取销毁任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") String taskId) throws JsonProcessingException {
        return AjaxResult.success(archiveDesTaskService.selectArchiveDesTaskByTaskId(taskId));
    }

    /**
     * 新增销毁任务
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:add')")
    @Log(title = "销毁任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveDesTask archiveDesTask) {
        return toAjax(archiveDesTaskService.insertArchiveDesTask(archiveDesTask));
    }

    /**
     * 修改销毁任务
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:edit')")
    @Log(title = "销毁任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveDesTask archiveDesTask) {
        return toAjax(archiveDesTaskService.updateArchiveDesTask(archiveDesTask));
    }

    /**
     * 删除销毁任务
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:remove')")
    @Log(title = "销毁任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable String[] taskIds) {
        return toAjax(archiveDesTaskService.deleteArchiveDesTaskByTaskIds(taskIds));
    }

    /**
     * 销毁任务结果上报接口
     */
    @ApiOperation("销毁任务结果上报接口")
    @PostMapping("/archiveDesTaskResultReport")
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesTask:archiveDesTaskResultReport')")
    public AjaxResult archiveDesTaskResultReport(@RequestBody ArchiveDesTask archiveDesTask) throws JsonProcessingException {
        if (null == archiveDesTask) {
            return AjaxResult.error("借阅任务信息为空，请检查重试！");
        }
        if (null == archiveDesTask.getDesNo()) {
            return AjaxResult.error("任务单号信息为空，请检查重试！");
        }
        return AjaxResult.success(archiveDesTaskService.archiveDesTaskResultReport(archiveDesTask));
    }
}
